﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QLKS
{
    public partial class frloaiphong : Form
    {
        public frloaiphong()
        {
            InitializeComponent();
        }

        private DataTable _dSLoaiPhg;

        internal DataTable DSLoaiPhg
        {
            get { return _dSLoaiPhg; }
            set { _dSLoaiPhg = value; }
        }

        private void buttonX4_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frloaiphong_Load(object sender, EventArgs e)
        {
            DSLoaiPhg = BUS.XuLyLoaiPhong.TimToanBoLoaiPhong();
            dgvLoaiPhong.DataSource = DSLoaiPhg;
        }

        private void dgvLoaiPhong_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int index = dgvLoaiPhong.SelectedRows[0].Index;

            DataRow dr = DSLoaiPhg.Rows[index];

            txtMaLoai.Text = dr["MaLoaiPhong"].ToString();
            txtLoaiPhong.Text = dr["LoaiPhong"].ToString();
            txtGiaTien.Text = dr["GiaTien"].ToString();
            txtSTT.Text = dr["STT"].ToString();
        }

        private void buttonX3_Click(object sender, EventArgs e)
        {
            if (dgvLoaiPhong.SelectedRows.Count > 0)
            {
                if (!BUS.XuLyLoaiPhong.XoaLoaiPhong(txtMaLoai.Text))
                {

                }
            } 
            else
            {
                MessageBox.Show("Ban chua chon loai phong");
            }
            frloaiphong_Load(sender, e);
        }

        private void buttonX2_Click(object sender, EventArgs e)
        {
            if (dgvLoaiPhong.SelectedRows.Count > 0)
            {
                int sothutu = int.Parse(txtSTT.Text);
                DTO.CLOAIPHONG lp = new DTO.CLOAIPHONG();
                lp.GiaTien = long.Parse(txtGiaTien.Text);
                lp.MaLoaiPhong = txtMaLoai.Text;
                lp.LoaiPhong = txtLoaiPhong.Text;
                if (!BUS.XuLyLoaiPhong.SuaTTLoaiPhong(lp,sothutu))
                {
                }
            }
            else
            {
                MessageBox.Show("Ban chua chon loai phong");
            }
            frloaiphong_Load(sender, e);
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            try
            {
                DTO.CLOAIPHONG lp = new DTO.CLOAIPHONG();
                lp = BUS.XuLyLoaiPhong.TimLoaiPhongTheoMaLoaiPhong(txtMaLoai.Text);

                if (lp.STT > 0)
                {
                    MessageBox.Show("Loai phong nay da ton tai.");
                }
                else
                {
                    lp = new DTO.CLOAIPHONG();
                    lp.MaLoaiPhong = txtMaLoai.Text;
                    lp.LoaiPhong = txtLoaiPhong.Text;
                    lp.GiaTien = long.Parse(txtGiaTien.Text);

                    if (!BUS.XuLyLoaiPhong.ThemLoaiPhong(lp))
                    {
                    }
                }
            }
            catch (System.Exception )
            {
            	
            }
            frloaiphong_Load(sender, e);
        }
        
    }
}
